﻿using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace Windows8Accelerator.Core.Xaml.Converters
{
    public class StringLengthToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var invert = false;
            if (parameter is string)
                bool.TryParse((string)parameter, out invert);

            var isEmpty = string.IsNullOrEmpty(value as string);
            if (invert)
                isEmpty = !isEmpty;
            return isEmpty ? Visibility.Collapsed : Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            return value;
        }
    }
}
